package boundarys;

import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JButton;

import ccrm.BoundryControl;
import controllers.UserController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

import entitys.Session;

import java.awt.Font;
import java.awt.Color;
import java.io.IOException;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class DMGUI extends AbstractGUI{

	private JFrame frmCcrmDM;
	private String userid;
	private String userpw;
	

	/**
	 * Create the application.
	 */
	public DMGUI(String userid, String userpw) {
		this.userid = userid;
		this.userpw = userpw;
		initialize();
		initGUI(frmCcrmDM);
		frmCcrmDM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{96, 254, 91, 0};
		gridBagLayout.rowHeights = new int[]{50, 43, 55, 55, 55, 43, 32, 37, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmCcrmDM.getContentPane().setLayout(gridBagLayout);
		
		JButton ManageClientsBtn = new JButton("Manage Clients");
		ManageClientsBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new ManageClientsGUI();
				}
			}
		});
		
		JLabel lblDepartmentOfMarketing = new JLabel("Department of Marketing Panel");
		lblDepartmentOfMarketing.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		GridBagConstraints gbc_lblDepartmentOfMarketing = new GridBagConstraints();
		gbc_lblDepartmentOfMarketing.fill = GridBagConstraints.BOTH;
		gbc_lblDepartmentOfMarketing.insets = new Insets(0, 0, 5, 5);
		gbc_lblDepartmentOfMarketing.gridx = 1;
		gbc_lblDepartmentOfMarketing.gridy = 0;
		frmCcrmDM.getContentPane().add(lblDepartmentOfMarketing, gbc_lblDepartmentOfMarketing);
		GridBagConstraints gbc_ManageClientsBtn = new GridBagConstraints();
		gbc_ManageClientsBtn.fill = GridBagConstraints.BOTH;
		gbc_ManageClientsBtn.insets = new Insets(0, 0, 5, 5);
		gbc_ManageClientsBtn.gridx = 1;
		gbc_ManageClientsBtn.gridy = 2;
		frmCcrmDM.getContentPane().add(ManageClientsBtn, gbc_ManageClientsBtn);
		ManageClientsBtn.setVisible(true);
		
		JButton SMPBtn = new JButton("Set Marketing Patterns");
		SMPBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				{
					if(BoundryControl.GUIArr.size()==getIndex()+1)
					{
						new SetMarketingPatternsGUI();
					}
				}
			}
		});
		GridBagConstraints gbc_SMPBtn = new GridBagConstraints();
		gbc_SMPBtn.fill = GridBagConstraints.BOTH;
		gbc_SMPBtn.insets = new Insets(0, 0, 5, 5);
		gbc_SMPBtn.gridx = 1;
		gbc_SMPBtn.gridy = 3;
		frmCcrmDM.getContentPane().add(SMPBtn, gbc_SMPBtn);
		SMPBtn.setVisible(true);
		
		JButton WeeklyAnalysisBtn = new JButton("Weekly Analysis");
		WeeklyAnalysisBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new WeeklyAnalysisGUI();
				}
			}
		});
		GridBagConstraints gbc_WeeklyAnalysisBtn = new GridBagConstraints();
		gbc_WeeklyAnalysisBtn.fill = GridBagConstraints.BOTH;
		gbc_WeeklyAnalysisBtn.insets = new Insets(0, 0, 5, 5);
		gbc_WeeklyAnalysisBtn.gridx = 1;
		gbc_WeeklyAnalysisBtn.gridy = 4;
		frmCcrmDM.getContentPane().add(WeeklyAnalysisBtn, gbc_WeeklyAnalysisBtn);
		WeeklyAnalysisBtn.setVisible(true);
		
		
		JButton logOut = new JButton("Log Out");
		logOut.setFont(new Font("Tahoma", Font.BOLD, 11));
		logOut.setForeground(Color.RED);
		logOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					goBack();
					UserController.LogoutUser(getUserid(), getUserpw());					
				}
			}
		});
		
		
		
		
		
		
		GridBagConstraints gbc_logOut = new GridBagConstraints();
		gbc_logOut.fill = GridBagConstraints.BOTH;
		gbc_logOut.insets = new Insets(0, 0, 5, 5);
		gbc_logOut.gridx = 0;
		gbc_logOut.gridy = 7;
		frmCcrmDM.getContentPane().add(logOut, gbc_logOut);
		logOut.setVisible(true);
		frmCcrmDM.setVisible(true);
	}

	public String getUserpw() {
		return userpw;
	}

	public void setUserpw(String userpw) {
		this.userpw = userpw;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCcrmDM = new JFrame();
		frmCcrmDM.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				UserController.LogoutUser(getUserid(), getUserpw());
			}
		});
		frmCcrmDM.setResizable(false);
		frmCcrmDM.setTitle("CCRM>Department of Marketing Management");
		frmCcrmDM.setBounds(100, 100, 437, 391);
		frmCcrmDM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}

	@Override
	public void getReply(Object r) {
		// TODO Auto-generated method stub

		
	}
}
